$(function () {
    $("#jqGrid").jqGrid({
        url: 'sys/config/list',
        datatype: "json",
        colModel: [			
			{ label: '数据库类型', name: 'databaseType', width: 80, key: true },
			{ label: '映射关系:jdbcOrMybatis', name: 'jdbcOrMybatis', width: 80},
			{ label: '是否使用Redis', name: 'isRedisCache', width: 80 },
            { label: '是否使用Dubbo', name: 'isDubbo', width: 80 },
            { label: '是否使用SpringMVC', name: 'isSpringMVC', width: 80 },
            { label: '只生成界面Val', name: 'pageVal', width: 80 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50,100,200],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
            databaseType: '',
            jdbcOrMybatis: '',
            isRedisCache:'',
            isDubbo: '',
            isSpringMVC:'',
            pageVal:''
		}
	},
    computed: {
        filterParamsStr: function () {
            var params = {}
            var paramsStr = ''
            if (this.q.databaseType) {
                params.databaseType = this.q.databaseType
            } else {
                delete params.databaseType
            }
            if (this.q.jdbcOrMybatis) {
                params.jdbcOrMybatis = this.q.jdbcOrMybatis
            } else {
                delete params.jdbcOrMybatis
            }
            if (this.q.isRedisCache) {
                params.isRedisCache = this.q.isRedisCache
            } else {
                delete params.isRedisCache
            }
            if (this.q.isDubbo) {
                params.isDubbo = this.q.isDubbo
            } else {
                delete params.isDubbo
            }
            if (this.q.isSpringMVC) {
                params.isSpringMVC = this.q.isSpringMVC
            } else {
                delete params.isSpringMVC
            }
            if (this.q.pageVal) {
                params.pageVal = this.q.pageVal
            } else {
                delete params.pageVal
            }

            console.log(params)
            for(var key in params) {
                paramsStr += '&' + key + '=' + params[key]
            }
            return paramsStr
        }
    },
	methods: {
        config: function() {

            $.ajax({
                url: "sys/config/update?" +  this.filterParamsStr,
                type:'get',
                dataType:'json',
                success: function (data) {
                    if(data.code == 0){
                        location.reload()
                    }else {
                        alert(data.msg);
                    }

                }

            })

		}
	}

});

